package xyz.yuanjilu.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import xyz.yuanjilu.entity.OaLeaveEntity;
import xyz.yuanjilu.service.OaLeaveService;
import xyz.yuanjilu.utils.PageUtils;
import xyz.yuanjilu.utils.Query;
import xyz.yuanjilu.utils.R;


/**
 * 请假审批
 * 
 * @author 空空儿雪丽
 * @email KKOMGE@QQ.COM
 * @date 2017-11-01 15:53:23
 */
@RestController
@RequestMapping("oaleave")
public class OaLeaveController extends BaseFormController{
	@Autowired
	private OaLeaveService oaLeaveService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("oaleave:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<OaLeaveEntity> oaLeaveList = oaLeaveService.queryList(query);
		int total = oaLeaveService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(oaLeaveList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("oaleave:info")
	public R info(@PathVariable("id") Long id){
		OaLeaveEntity oaLeave = oaLeaveService.queryObject(id);
		
		return R.ok().put("oaLeave", oaLeave);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("oaleave:save")
	public R save(@RequestBody OaLeaveEntity oaLeave){
		oaLeaveService.save(oaLeave);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("oaleave:update")
	public R update(@RequestBody OaLeaveEntity oaLeave){
		oaLeaveService.update(oaLeave);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("oaleave:delete")
	public R delete(@RequestBody Long[] ids){
		oaLeaveService.deleteBatch(ids);
		
		return R.ok();
	}


	@RequestMapping("toFormInfo/{processDefinitionId}/{nodeId}/{businessKey}/{type}")
	public ModelAndView toFormInfo(@PathVariable String processDefinitionId,@PathVariable String nodeId,@PathVariable String businessKey,@PathVariable  String type) {
		Map<String, String> model = new HashMap<String, String>();
		model.put("id", businessKey);
		ModelAndView mv =new ModelAndView("oa/oaleaveform.html",model);
		return mv;
	}
	
}
